<template>
	<view class="page bg-fff">
		<up-gap height="20"></up-gap>
		<!-- <view class="title text-center fontBold bottom-10 top-10" v-if="detailData.title">{{ detailData.title }}</view> -->
		<rich-text :nodes="contentTxt"></rich-text>
		<up-gap height="40"></up-gap>
	</view>
</template>

<script setup>
import { ref } from "vue";
import { useUserInfoStore } from '@/store/index';
import { onLoad, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
import { getArticleDetailById } from '@/common/api/tools';

const userInfoStore = useUserInfoStore();

let articleId = ref('');
let contentTxt = ref('');
let detailData = ref({});


// 页面加载
onLoad((options) => {
	articleId.value = options.detailId;
	uni.$check_and_login(init)
})

// 分享到好友
onShareAppMessage(() => {
	return {
		title: detailData.value.title || '资格查询',
		path: `/pages/tools/policy-news/detail/index?detailId=${articleId.value}&puid=${userInfoStore.userInfo.id}`,
		imageUrl: detailData.value.image?.[0]?.url || ''
	}
})

// 分享到朋友圈
onShareTimeline(() => {
	return {
		title: detailData.value.title || '资格查询',
		query: `detailId=${articleId.value}&puid=${userInfoStore.userInfo.id}`
	}
})

//初始化
async function init() {
	try {
		const res = await getArticleDetailById(articleId.value);
		if(res.status !== 0) {
			uni.$u.toast(res.detail);
			return
		}
		contentTxt.value = res.detail.content.replace(/\<img/gi, '<img style="max-width: 100%;height: auto"');
		detailData.value = res.detail;
		articleId.value = res.detail.id;
	} catch (error) {}
}
</script>

<style lang="scss" scoped>
.page{
	min-height: 100vh;
	overflow: hidden;
	padding: 0 30rpx;
}
</style>